package Frame.battleanimation;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import VWorldGameStudio.FCAnimation;

import java.awt.*;

import static FCRendering.FCRMaster.fcv;

//防御动画
public class FangyuAni extends ABattleAni implements IBattleAni{

    FCAnimation fcAnimation;
    private String playName;
    int[] startpoints;
    int[] firePaintPoints;
    private int pngIndex = -1;
    private String targetName;
    /**
     * 就站出来防御一下就行了
     * @param name
     * @param startPoint
     */
    public FangyuAni(String name, String targetName, int[] startPoint, boolean isPlayerAttackMode){
        this.playName = name;
        this.startpoints = startPoint;
        this.targetName = targetName;//targetName是对保护他人的意思，
        this.isPlayerAttackMode = isPlayerAttackMode;
        fcAnimation = FCRMaster.animationLib.getAnimationOfID("fangyu");

        if(isPlayerAttackMode) {
            playerOffset[0] = (int) (20 * fcv.getProportion());
            startPoint[0] -= playerOffset[0];
        }else {
            playerOffset[0] = (int) (40 * fcv.getProportion());
            startPoint[0] += playerOffset[0];
        }
        if(fcAnimation != null && fcAnimation.getFirePngUrl().size() > 0){
            allFrames = 400 / 16;
        }else {
            allFrames = 20;
        }
    }


    @Override
    public void nextFrame(int frame) {
        if(fcAnimation != null) {
            int p = allFrames / fcAnimation.getFirePngUrl().size();
            int index = frame / p + 1;
            pngIndex = Math.min(index, fcAnimation.getFirePngUrl().size() - 1);
            if (firePaintPoints == null) {
                firePaintPoints = new int[2];
                firePaintPoints[0] = startpoints[0] + (int) (fcAnimation.firePngCenterOffsetX * fcv.getProportion());
                firePaintPoints[1] = startpoints[1] + (int) (fcAnimation.firePngCenterOffsetY * fcv.getProportion());
             }
        }
        if (frame == 5) {
        }
    }

    @Override
    public void paintBattleSceen(Graphics g, FCRMaster fcrMaster) {
        if (fcAnimation != null) {
            fire(g, fcrMaster);
        }
    }

    @Override
    public void fire(Graphics g, FCRMaster fcrMaster) {
        if(pngIndex != -1) {
            g.drawImage(fcAnimation.getFirePng().get(pngIndex), firePaintPoints[0], firePaintPoints[1],
                    (int) (fcAnimation.firePngSizeW * fcv.getProportion()), (int) (fcAnimation.firePngSizeH * fcv.getProportion()), fcrMaster);
        }
    }

    @Override
    public void flying(Graphics g, FCRMaster fcrMaster) {

    }

    @Override
    public void boom(Graphics g, FCRMaster fcrMaster) {

    }
}
